var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: ["提现", "充值"],
    array: ['微信余额'],
    current: 0,
    oppenId: 0//根据openID判断是普通用户还是专家  0是普通用户 1是专家
  },
  tab: function (e) {
    this.setData({
      current: e.currentTarget.dataset.index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    var uniacid = app.siteInfo.uniacid;
    this.setData({
      uniacid: uniacid,
    })
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Doctormoneytx',
      data: { openid: openid },
      success: function (res) {
        console.log(res.data.data)
        that.setData({
          zhuanmoney: res.data.data.money
        })
      },
      fail: function (err) {
        console.log(err)
      },

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },



  //普通用户提现
  formSubmit: function (e) {
    var that = this;
    var formobj = e.detail.value;
    formobj.openid = wx.getStorageSync('openid');
    var tx_cost = formobj.tx_cost
    var sj_cost = formobj.sj_cost
    console.log(tx_cost, sj_cost)
    let countmoney = that.data.countmoney

    if (e.detail.value.sj_cost.length == 0) {
      wx.showModal({
        content: '您的账户暂无金额',
      })
    } else if (e.detail.value.tx_cost.length == 0) {
      wx.showModal({
        content: '请输提现金额',
      })
    } else if (e.detail.value.tx_type == '' || e.detail.value.tx_type == null) {
      wx.showModal({
        content: '请选择提现方式',
      })
    } else if (tx_cost > sj_cost) {
      wx.showModal({
        content: '超出实际金额',
      })
    } else if (tx_cost < 1) {
      wx.showModal({
        content: '提现金额必须大于1',
      })
    }
    else {
      wx.showModal({
        title: '提示',
        content: ' 确认提交么？ ',
        success: function (res) {
          if (res.confirm) {
            console.log(res.confirm)
            console.log('用户点击确定');
            var sj_cost = e.detail.value.sj_cost;
            var tx_cost = e.detail.value.tx_cost;
            var tx_type = e.detail.value.tx_type;
            var openid = wx.getStorageSync('openid');
            app.util.request({
              url: 'entry/wxapp/SaveTx',
              data: {
                sj_cost: sj_cost,
                tx_cost: tx_cost,
                tx_type: tx_type,
                openid: openid
              },
              header: { 'Content-Type': 'application/json' },
              success: function (res) {
                console.log(res)

                if (res.data.code == 1) {
                  wx.showToast({
                    title: '提交失败',
                  })
                }
                else {
                  wx.showToast({
                    title: '提交成功',
                  })
                  wx.redirectTo({
                    url: '../my/my'
                  })
                }

              },

              fail: function (err) {
                console.log(err);
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
      //获取用户信息
    }
  },
  //普通用户充值
  czformSubmit: function (e) {
    var that = this;
    var formobj = e.detail.value;
    formobj.openid = wx.getStorageSync('openid');
  },
  //专家提现
  onformSubmit: function (e) {
    var that = this;
    var formobj = e.detail.value;
    formobj.openid = wx.getStorageSync('openid');
    var tx_cost = parseFloat(formobj.tx_cost)
    var sj_cost = parseFloat(formobj.sj_cost)
    console.log(tx_cost)
    let countmoney = that.data.countmoney

    if (e.detail.value.sj_cost.length == 0) {
      wx.showModal({
        content: '您的账户暂无金额',
      })
    } else if (e.detail.value.tx_cost.length == 0) {
      wx.showModal({
        content: '请输提现金额',
      })
    } else if (e.detail.value.tx_type == '' || e.detail.value.tx_type == null) {
      wx.showModal({
        content: '请选择提现方式',
      })
    } else if (tx_cost > sj_cost) {
      wx.showModal({
        content: '超出实际金额',
      })
    } else if (tx_cost < 1) {
      wx.showModal({
        content: '提现金额必须大于1',
      })
    }
    else {
      wx.showModal({
        title: '提示',
        content: ' 确认提交么？ ',
        success: function (res) {
          if (res.confirm) {
            console.log(res.confirm)
            console.log('用户点击确定');
            var sj_cost = e.detail.value.sj_cost;
            var tx_cost = e.detail.value.tx_cost;
            var tx_type = e.detail.value.tx_type;
            var openid = wx.getStorageSync('openid');
            app.util.request({
              url: 'entry/wxapp/SaveTx',
              data: {
                sj_cost: sj_cost,
                tx_cost: tx_cost,
                tx_type: tx_type,
                openid: openid
              },
              header: { 'Content-Type': 'application/json' },
              success: function (res) {
                console.log(res)

                if (res.data.code == 1) {
                  wx.showToast({
                    title: '提交失败',
                  })
                }
                else {
                  wx.showToast({
                    title: '提交成功',
                  })
                  wx.redirectTo({
                    url: '../my/my'
                  })
                }

              },

              fail: function (err) {
                console.log(err);
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
      //获取用户信息
    }
  },

  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })

  },
  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
})